package com.flea.hclv.controller;

import com.flea.hclv.model.entity.HTicketDeptOrder;
import com.flea.hclv.service.HTicketDeptOrderService;
import com.flea.hclv.util.ServerResponse;
import com.flea.system.bean.FleaPage;
import com.flea.system.entity.OrgDept;
import com.flea.system.platform.session.FleaOrgUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @program: project
 * @description: 组团社购买门票记录
 * @author: shiliqiang
 * @create: 2018-12-31 10:32
 * @version: 1.0
 */
@Controller
@RequestMapping("/flea/hclv/ticket/order/item")
public class HTicketDeptOrderController {

    @Autowired
    private HTicketDeptOrderService hTicketDeptOrderItemService;

    //创建组团社购买门票订单 （包括 多个类型门票集合，支付信息）
    @ResponseBody
    @RequestMapping("createDeptTicketOrder")
    public ServerResponse<String> pay(HttpServletRequest request, String model) throws Exception {
        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<String> response = hTicketDeptOrderItemService.save(model, userId);
        return response;
    }

    //通过景点id和部门id 获取该部门某一景点的所有门票信息（门票类型，库存，价格,以及账户信息）
    @ResponseBody
    @RequestMapping("selectBySpotIdAndDeptId")
    public ServerResponse<Map<String, Object>> selectBySpotIdAndDeptId(HttpServletRequest request, String spotTicketId) {
        String userId = FleaOrgUtils.getCurUserUuid(request);
        ServerResponse<Map<String, Object>> response = hTicketDeptOrderItemService.selectBySpotIdAndDeptId(spotTicketId, userId);
        return response;
    }

    //组团社 供应商公用接口 （门票订单列表）
    @ResponseBody
    @RequestMapping("selectOrderInfo")
    public ServerResponse<FleaPage<HTicketDeptOrder>> selectOrderInfo(HttpServletRequest request, FleaPage<HTicketDeptOrder> paging,
                                                                      @RequestParam(value = "spotName", defaultValue = "") String spotName) {

        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);

        if (currentUserDept == null) {
            return ServerResponse.createByErrorMessage("部门信息不能为空");
        }
        String serviceType = currentUserDept.getServiceType();
        ServerResponse<FleaPage<HTicketDeptOrder>> response = hTicketDeptOrderItemService.selectByDeptId(currentUserDept.getDeptUuid(), paging.getCurPage(), paging.getPageSize(),spotName,serviceType);
        return response;
    }

    ////组团社供应商公用接口  门票订单详情（包括门票类型数量，支付信息）
    @ResponseBody
    @RequestMapping("selectOrderItemInfo")
    public ServerResponse<Map<String, Object>> selectOrderInfo(HttpServletRequest request, String orderId) {
//        OrgDept currentUserDept = FleaOrgUtils.getCurrentUserDept(request);
//        if (currentUserDept==null){
//            return ServerResponse.createByErrorMessage("部门信息不能为空");
//        }
        ServerResponse<Map<String, Object>> response = hTicketDeptOrderItemService.selectByOrderId(orderId);
        return response;
    }

}
